package com.zhoug.zmui3demo.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.zhoug.zmui3.chart.ZMUIDashboardView;
import com.zhoug.zmui3.chart.ZMUIDashboardView1;
import com.zhoug.zmui3demo.R;

import java.util.Random;

import androidx.appcompat.app.AppCompatActivity;

public class DashboardViewActivity extends AppCompatActivity {

    private ZMUIDashboardView mZMUIDashboardView;
    private ZMUIDashboardView1 mZMUIDashboardView1;
    private Button mBtnStartAnim;
    private Button mBtnSetValue;
    private EditText mEtArc;
    private Button mBtnSetArc;
    private Button mBtnPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard_view);
        findViews();

        init();
    }

    private void findViews() {
        mZMUIDashboardView = findViewById(R.id.ZMUIDashboardView);
        mBtnStartAnim = findViewById(R.id.btn_startAnim);
        mBtnSetValue = findViewById(R.id.btn_setValue);
        mEtArc = findViewById(R.id.et_arc);
        mBtnSetArc = findViewById(R.id.btn_setArc);
        mZMUIDashboardView1 = findViewById(R.id.ZMUIDashboardView1);
        mBtnPosition = findViewById(R.id.btn_position);
    }

    private void init(){
        mZMUIDashboardView.setValueFormat(new ZMUIDashboardView.ValueFormat() {
            @Override
            public String getValueFormat(float value) {
                int a= (int) value;
                return a+"%";
            }
        });



        mBtnStartAnim.setOnClickListener(v->{
            mZMUIDashboardView.startAnim();
            mZMUIDashboardView1.startAnim(0);
        });
        mBtnSetValue.setOnClickListener(v->{
            Random random=new Random();
            int i = random.nextInt(101);
            mBtnSetValue.setText("随机设置value:"+i);
            mZMUIDashboardView.setValue(i );
            mZMUIDashboardView.startAnim();
            mZMUIDashboardView1.setValue(i);
            mZMUIDashboardView1.startAnim(0);
        });

        mBtnSetArc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = mEtArc.getText().toString();
                try {
                    int arc = Integer.parseInt(s);
                    mZMUIDashboardView.setDegrees(arc);
                    mZMUIDashboardView1.setDegrees(arc);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }


            }
        });

        mBtnPosition.setOnClickListener(v->{
            int labelPosition = mZMUIDashboardView1.getLabelPosition();
            if(labelPosition==ZMUIDashboardView1.LABEL_POSITION_OUTER){
                mZMUIDashboardView1.setLabelPosition(ZMUIDashboardView1.LABEL_POSITION_INNER);
            }else{
                mZMUIDashboardView1.setLabelPosition(ZMUIDashboardView1.LABEL_POSITION_OUTER);
            }

        });
    }
}